package cn.ranko.site.action;

import cn.ranko.bean.easyui.DataGrid;
import cn.ranko.bean.easyui.Messager;
import cn.ranko.site.model.SysMenus;
import cn.ranko.site.service.SysMenusService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Created by ZJ08 on 2016/8/30.
 *
 * 菜单管理
 *
 */
@Controller
@RequestMapping("/site-menus")
public class SysMenusAction {

    @Autowired
    SysMenusService menusService;

    @RequiresPermissions("site-menus:view")
    @RequestMapping(value = "index.action",method = RequestMethod.GET)
    public String index() {
        return "site/menus/index";
    }

    @RequiresPermissions("site-menus:view")
    @RequestMapping(value = "loadList.action",method = RequestMethod.GET)
    @ResponseBody
    public DataGrid loadList(){
        List<Map> menusList = menusService.selectAll();

        DataGrid dataGrid = new DataGrid();
        dataGrid.setRows(menusList);
        dataGrid.setTotal(menusList.size());

        return dataGrid;
    }

    /**
     * 菜单添加、界面显示
     * @return
     */
    @RequiresPermissions("site-menus:add")
    @RequestMapping(value = "showadd.action",method = RequestMethod.GET)
    public String showadd(){
        return "site/menus/showedit";
    }

    /**
     * 菜单编辑、界面显示
     * @return
     */
    @RequiresPermissions("site-menus:edit")
    @RequestMapping(value = "showedit.action",method = RequestMethod.GET)
    public String showedit(){
        return "site/menus/showedit";
    }

    /**
     * 菜单保存操作
     * @return
     */
    @RequiresPermissions(value = {"site-menus:edit","site-menus:add"},logical = Logical.OR)
    @ResponseBody
    @RequestMapping(value = "save.action",method = RequestMethod.POST)
    public String save(){
        return "";
    }

    /**
     * 菜单删除操作
     *
     * @param ids
     * @return
     */
    @RequiresPermissions("site-menus:delete")
    @RequestMapping(value = "delete.action",method = RequestMethod.GET)
    @ResponseBody
    public Messager delete(String ids){
        Messager messager = new Messager();
        return messager;
    }

}
